package errs

import (
	"errors"
	"fmt"

	pkgerr "github.com/pkg/errors"
)

var (
	NotImplement = errors.New("未实现")
	NotSupport   = errors.New("不支持")
	RelativePath = errors.New("不允许使用相对路径访问")

	MoveBetweenTwoStorages = errors.New("无法在两个存储之间移动文件，请尝试复制")
	UploadNotSupported     = errors.New("不支持上传")

	MetaNotFound     = errors.New("元数据未找到")
	StorageNotFound  = errors.New("存储未找到")
	StreamIncomplete = errors.New("上传/下载流不完整，可能是网络问题")
	StreamPeekFail   = errors.New("流预览失败")

	UnknownArchiveFormat      = errors.New("未知的归档格式")
	WrongArchivePassword      = errors.New("归档密码错误")
	DriverExtractNotSupported = errors.New("驱动不支持解压")
)

func NewErr(err error, format string, a ...any) error {
	return fmt.Errorf("%w; %s", err, fmt.Sprintf(format, a...))
}

func IsNotFoundError(err error) bool {
	return errors.Is(pkgerr.Cause(err), ObjectNotFound) || errors.Is(pkgerr.Cause(err), StorageNotFound)
}

func IsNotSupportError(err error) bool {
	return errors.Is(pkgerr.Cause(err), NotSupport)
}

func IsNotImplement(err error) bool {
	return errors.Is(pkgerr.Cause(err), NotImplement)
}
